<?php
namespace Home\Controller;
use Think\Controller;
echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">';

class UserCenterController extends Controller {
    public function register()
    {
    	if(!isset($_POST['act_register']))
    	{
            $region = D('Region');
            $reg_list = $region ->get_region(1);
            $this->assign('reg_list',$reg_list);

    		$this->display();
    	}
    	else
    	{
    		$res['mobile_phone'] = I('post.mobile_phone','');
    		$res['user_name']    = I('post.user_name','');
    		$res['sex']          = I('post.sex','');
            $res['birthday']     = I('post.bir_year','').'-'.I('post.bir_month','').'-'.I('post.bir_day','');
            $res['car_no']       = I('post.car_no','');
            $res['province']     = I('post.province','');
            $res['city']         = I('post.city','');
    		$res['district']     = I('post.district','');

    		$users = D('Users');
            $user_id = $users->get_register($res);
            //dump($user_id);
            if($user_id)
            {
                session('user_id',$user_id);  
                session('user_name',$res['user_name']);
                $this->success('注册成功，返回首页',U('Index/index'),3);
            }
            else
            {
                $this->error('注册失败，请重新注册',U('Register/register'),5);
            }
    	}
        
    }

    public function member()
    {
        $user_id = session('user_id') ? session('user_id') : 1;//暂时代替，做微信登录时修改
        if($user_id)
        {
            $users = D('Users');
            $user_info = $users->get_userinfo($user_id);
            $this->assign('u_info',$user_info);
            $this->display();
        }
        else
        {
            $this->error('请先登录',U('Index/index'),3);
        }
        
    }

    public function my_card()
    {
        $user_id = session('user_id') ? session('user_id') : 1;//暂时代替，做微信登录时修改
        if($user_id)
        {
            $types = D('CardType');
            $card_type = $types->select();
            $this->assign('card_type',$card_type);
            $this->display();
        }
        else
        {
            $this->error('请先登录',U('Index/index'),3);
        }
    }
    public function own_card()
    {
        $user_id    = session('user_id') ? session('user_id') : 1;//暂时代替，做微信登录时修改
        $type_id    = I('get.type_id','');
        $is_status  = I('get.sid',1);

        $user = D('UserCard');
        $own_list = $user->get_usercard($type_id,$user_id,$is_status);
        $this->assign('own_list',$own_list);
        $this->assign('tid',$type_id);
        $this->display();
    }
}